import api from '@/store/api';
import i18n from '@/i18n';
const { t } = i18n.global as any;

export const useFactoryResetStore = defineStore('factoryReset', () => {
  const resetToDefaults = async () => {
    return await api
      .post(
        '/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults',
        {
          ResetToDefaultsType: 'ResetAll',
        },
        undefined,
      )
      .then(() => t('pageFactoryReset.toast.resetToDefaultsSuccess'))
      .catch((error) => {
        console.log('Factory Reset: ', error);
        throw new Error(
          t('pageFactoryReset.toast.resetToDefaultsError') as string,
        );
      });
  };
  const resetBios = async () => {
    return await api
      .post(
        '/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios',
        undefined,
        undefined,
      )
      .then(() => t('pageFactoryReset.toast.resetBiosSuccess'))
      .catch((error) => {
        console.log('Factory Reset: ', error);
        throw new Error(t('pageFactoryReset.toast.resetBiosError') as string);
      });
  };

  return { resetToDefaults, resetBios };
});
